import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Created by IntelliJ IDEA.
 * User: roll
 * Date: 8/19/11
 * Time: 2:19 PM
 * To change this template use File | Settings | File Templates.
 */

public class Kolor {
    public static String TNSName = "C91DEMO";
    public static String UserID = "szkolenie";
    public static String Passwd = "szkolenie";
    public static String Url = "10.0.201.1";
    /*public static String TNSName = "C91DEMO";
    public static String UserID = "szkolenie";
    public static String Passwd = "szkolenie";
    public static String Url = "10.0.1.201";*/

    public boolean isConnected = false;
    public Connection connection = null;

    /*private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("TopLevelDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Create the menu bar.  Make it have a green background.
        JMenuBar greenMenuBar = new JMenuBar();
        greenMenuBar.setOpaque(true);
        greenMenuBar.setBackground(new Color(154, 165, 127));
        greenMenuBar.setPreferredSize(new Dimension(200, 20));

        //Create a yellow label to put in the content pane.
        JLabel yellowLabel = new JLabel();
        yellowLabel.setOpaque(true);
        yellowLabel.setBackground(new Color(248, 213, 131));
        yellowLabel.setPreferredSize(new Dimension(200, 180));

        //Set the menu bar and add the label to the content pane.
        frame.setJMenuBar(greenMenuBar);
        frame.getContentPane().add(yellowLabel, BorderLayout.CENTER);

        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }         */

    public void OpenConn() {
        if (!isConnected) {
            try {
                // Load the JDBC driver
                String driverName = "oracle.jdbc.driver.OracleDriver";
                Class.forName(driverName);

                // Create a connection to the database
                String serverName = Url;
                String portNumber = "1521";
                String sid = TNSName;
                String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
                String username = UserID;
                String password = Passwd;
                connection = DriverManager.getConnection(url, username, password);
            } catch (ClassNotFoundException e) {
                // Could not find the database driver
                System.out.println("Could not find the database driver");

            } catch (SQLException e) {
                // Could not connect to the database
                System.out.println(" Could not connect to the database");
            }
            if (connection != null) {
                isConnected = true;
                // return connection;
            } else {
                isConnected = false;
                //  return connection;
            }
        }
    }

    public void CloseConn(/*Connection connection*/) {
        if (isConnected) {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
            isConnected = false;
        }
    }

    /* public static void main(String[] args) {
 /*javax.swing.SwingUtilities.invokeLater(new Runnable() {
     public void run() {
         createAndShowGUI();
     }
 });   **/

    /*   boolean isConnected;
Connection connection = OpenConn();
System.out.println("");
if (connection != null) {
    CloseConn(connection);
}    */
}

